<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>控制器定义 升降排序</title>
    <script src="../angular.js"></script>
</head>
<body>
    <div ng-app="gg" ng-controller="ctrl">
        {{data}}
        <br />
        <button type="button" ng-click="orderBy(false)">升序</button>
        <button type="button" ng-click="orderBy(true)">降序</button>
    </div>


<script>
    var mod = angular.module('gg', []);
    mod.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) {
        $scope.data = [
            {id: 1 ,click : 100, title : '美文'},
            {id: 2 ,click : 80, title : '英语'},
            {id: 3 ,click : 150, title : '高数'}
        ]

        $scope.orderBy = function (item) {
            $scope.data = $filter('orderBy')($scope.data, 'id', item)
        }
    }])
</script>
</body>
</html>